package com.bei_en.teacher.admin.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.bei_en.teacher.admin.model.learn.condition.LearnReportCondition;
import com.bei_en.teacher.admin.model.learn.vo.LearnReportVo;
import com.bei_en.teacher.admin.model.user.condition.UserFinanceCondition;
import com.bei_en.teacher.admin.model.user.vo.UserFinanceVo;
import com.bei_en.teacher.admin.service.learn.LearnReportService;
import com.bei_en.teacher.admin.service.user.UserFinanceService;

public class StartWorkJob   {
	
	
	
	@Autowired
	UserFinanceService userFinanceService;
	@Autowired
	LearnReportService learnReportService;
	public void startWork() {
		LearnReportCondition learnReportCondition=new LearnReportCondition();
		learnReportCondition.setCreateTime1(new Date(new Date().getTime()-86400*7*1000));
		learnReportCondition.setCreateTime2(new Date());
		learnReportCondition.setOrderDirection("desc");
		learnReportCondition.setOrderField("yes_fraction");
		List<LearnReportVo> learnReportVos= learnReportService.findLearnReportPage(learnReportCondition);
		if(!learnReportVos.isEmpty()){
		int user_id=	learnReportVos.get(0).getUserId();
		UserFinanceCondition  userFinanceCondition=new UserFinanceCondition();
		userFinanceCondition.setUserId(user_id);
		List<UserFinanceVo> userFinanceVos=	userFinanceService.findUserFinancePage(userFinanceCondition);
		if(!userFinanceVos.isEmpty()){
			UserFinanceVo userFinanceVo=	userFinanceVos.get(0);
			userFinanceVo.setMoney(100d);
			userFinanceVo.setNote("周榜冠军奖励");
			userFinanceVo.setSource(0);
			userFinanceVo.setRemaining(userFinanceVo.getRemaining()+100);
			userFinanceVo.setCreateTime(new Date());
			userFinanceService.insert(userFinanceVo);
		}else{
			UserFinanceVo userFinanceVo=new UserFinanceVo();
			userFinanceVo.setUserId(user_id);
			userFinanceVo.setUserIds(0);
			userFinanceVo.setMoney(100d);
			userFinanceVo.setType(1);
			userFinanceVo.setSource(0);
			userFinanceVo.setNote("周榜冠军奖励");
			userFinanceVo.setStatus(1);
			userFinanceVo.setRemaining(100d);
			userFinanceVo.setCreateTime(new Date());
			userFinanceService.insert(userFinanceVo);
		}

		}
		
	}
}